//
//  BuyItemCollectionView.swift
//  HappyToSee
//
//  Created by Wade on 2024/7/5.
//

import Foundation
import UIKit
import QMUIKit
class KEClassifyListViewCell :UICollectionViewCell{
    var anwserBtn:UIButton?
    var indexLabel:UILabel?
    
    private var _cellSelect:Bool = false
    private var _categoryDetail:KEClassifyCategoriesDetail?
    
    var categoryDetail:KEClassifyCategoriesDetail? {
        get{
            return _categoryDetail
        }
        
        set{
            _categoryDetail = newValue
            indexLabel?.text = (_categoryDetail?.word_category_en ?? "") + "/" + (_categoryDetail?.word_category_zh ?? "")
            anwserBtn?.sd_setImage(with: .init(string:_categoryDetail?.word_category_icon_url ?? ""), for: .normal)
        }
    }
    
    var setCellSelect:Bool  {
        get{
            return _cellSelect
        }
        
        set{
            _cellSelect = newValue
            if _cellSelect == false{
                let color = UIColor.qmui_color(withHexString: "#E2B86B")
                self.indexLabel?.textColor = color
              
                
            }else{
                let color = UIColor.qmui_color(withHexString: "#46310D")
                self.indexLabel?.textColor = color
            }
        }
    }
    
    
    
    
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupSubViews()
    }
    
    func setupSubViews(){
        self.backgroundColor = .white;
        
        let anwserBtn = UIButton()
        self.addSubview(anwserBtn)
        self.anwserBtn = anwserBtn
        anwserBtn.isUserInteractionEnabled = false
        anwserBtn.imageView?.contentMode = .scaleAspectFill
        anwserBtn.titleLabel?.textAlignment = .center
        anwserBtn.titleLabel?.font = .systemFont(ofSize: 35)
        anwserBtn.titleLabel?.numberOfLines = 0;
        anwserBtn.setTitleColor(.black, for: .normal)
        anwserBtn.setImage(.init(named: "apple-pic"), for: .normal)
        anwserBtn.snp.makeConstraints { make in
            make.centerX.equalTo(self)
            make.width.height.equalTo(self.qmui_width - 30)
            make.top.equalTo(self.snp.top).offset(10)
        }
   
        let label1 = UILabel()
        label1.textColor = UIColor.qmui_color(withHexString: "#333")
        label1.textAlignment = .center
        label1.numberOfLines = 2
        label1.font = .boldSystemFont(ofSize: 15)
        label1.text = "apple"
        self.addSubview(label1)
        label1.snp.makeConstraints { make in
            make.left.equalTo(self).offset(20)
            make.right.equalTo(self).offset(-20)
            make.top.equalTo(anwserBtn.snp.bottom).offset(10)
            make.centerX.equalTo(self)
        }
        self.indexLabel = label1
        
    }
    
    
    override func layoutSubviews() {
        
    }
}
